package logic

import (
	"context"
	"zk/product_zy17/models/mysql"

	"zk/product_zy17/productRpc/internal/svc"
	"zk/product_zy17/productRpc/productRpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddProductLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddProductLogic {
	return &AddProductLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddProductLogic) AddProduct(in *productRpc.AddProductRequest) (*productRpc.AddProductResponse, error) {
	// todo: add your logic here and delete this line

	good := mysql.Product{
		Image:  in.Image,
		Title:  in.Title,
		Info:   in.Info,
		Price:  float64(in.Price),
		UserId: in.UserId,
	}

	mysql.DB.Create(&good)

	return &productRpc.AddProductResponse{
		Id: int64(good.ID),
	}, nil
}
